#include <conversion.h>

#define is_num(c)	(c>='0' && c<='9')
#define is_ALPHA(c)	(c>='A' && c<='F')
#define is_alpha(c)	(c>='a' && c<='f')

void conversion::hex2bin(BYTE *str, BYTE * &array, int size)
{
	for(int i=0; i < size;)
	{
		unsigned char ch1, ch2;
		unsigned char dig1, dig2;
		ch1 = *(str + i++);
		ch2 = *(str + i++);
		if(is_num(ch1)) 
			dig1 = ch1 - '0';
		else if(is_ALPHA(ch1)) 
			dig1 = ch1 - 'A' + 10;
		else if(is_alpha(ch1)) 
			dig1 = ch1 - 'a' + 10;
		if(is_num(ch2)) 
			dig2 = ch2 - '0';
		else if(is_ALPHA(ch2)) 
			dig2 = ch2 - 'A' + 10;
		else if(is_alpha(ch2)) 
			dig2 = ch2 - 'a' + 10;
		*(array + (i / 2 - 1)) = dig1 * 16 + dig2;
	}
}